<?php include('header.php'); ?>
<!-- additional javascript hear -->
<script src="http://maps.google.com/maps?file=api&amp;v=3&amp;sensor=false&amp;key=ABQIAAAA1QnAxBtPWpvkkIJ1M7uNRhSaZr1EoDksNVh5CWAzOfD4zrQihBTtbZTHEHq4q97m9-r8YVi8kTiliA" type="text/javascript"></script>

<script type="text/javascript" src="<?=base_url();?>application/scripts/jquery-1.4.2.min.js"></script>

<!-- begine tipsy --> 
<link rel="stylesheet" href="<?=base_url();?>application/css/tipsy.css" type="text/css" />
<script type="text/javascript" src="<?=base_url();?>application/scripts/jquery.tipsy.js"></script>
<!-- end tipsy -->

<script type="text/javascript" src="<?=base_url();?>application/scripts/zoom.js"></script>
<script type="text/javascript" src="<?=base_url();?>application/scripts/walleffect.js"></script>
<!-- user map -->
<script type="text/javascript">
var lat = "<?=$lat;?>";
var lng = "<?=$lng;?>";

    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(lat, lng), 13);
		var point = new GLatLng(lat,lng);
		var marker = new GMarker(point);
		map.addOverlay(marker);
        }
      }
</script>

<script type="text/javascript">
$(function() {
//More Button
$('.more').live("click",function() 
{
var ID = $(this).attr("id");
if(ID)
{
$("#more"+ID).html('<img src="<?=base_url();?>application/images/spinner.gif" />');

$.ajax({
type: "POST",
url: "loadmore/more",
data: "lastmsg="+ ID, 
cache: false,
success: function(html){
$("#updates").append(html);
$("#more"+ID).remove();
}
});
}
else
{
$(".morebox").html('ไม่มีโพสต์แล้ว');

}


return false;


});
});

</script>

<script type='text/javascript'>
  $(function() {
	 $('.tipsy-fade').tipsy({fade: true});
 });
</script>

<style>
	.morebox
	{
	font-weight:bold;
	color:#333333;
	background:#F4FFF4;
	text-align:center;
	border:solid 1px #CFCFCF;
	padding:8px;
	margin-top:8px;
	margin-bottom:8px;
	-moz-border-radius: 6px;-webkit-border-radius: 6px;
	}
	.morebox a{ color:#333333; text-decoration:none}
	.morebox a:hover{ color:#400000; text-decoration:none}
	</style>
</head>
<body onLoad="initialize();" onUnload="GUnload();">
<div id="wrapper">
<!-- menu -->
<?php include('menu.php'); ?>
<!-- end menu -->

<!-- navigator -->
<?php include('navigator.php'); ?>
<!-- nav end -->

<div class="container">
<div class="span-960">
<div class="item">
<h2>
<?=$username;?>
<img src="<?php echo $avatar;?>" alt="<?=$username;?>">
</h2>
<p>
<?=$about;?>
<br />
</p>
</div>

<?php if ($notifications > 0) { ?>
<div class="item">
<h2><img src="<?=base_url() . 'application/images/notifications.jpg'?>">Notifications</h2>
<p><a href="<?=base_url() . 'profile/notifications'?>">คุณมี <?=$notifications;?> คำร้องขอติดตาม</a></p><br />
</div>
<? } ?>

<div class="item">
<h2>ตำแหน่งของ <?=$username;?></h2>
<?php
if($lat == null && $lng == null)
	{
		echo "<p>ไม่สามารถแสดงแผนที่ได้ อาจเป็นเพราะคุณเพิ่งลงทะเบียน หรือคุณยังไม่ได้ระบุตำแหน่งของคุณ  กรุณาระบุโดยคลิ๊กที่เมนู ".anchor('profile/mymap', 'ระบุตำแหน่ง');
	}else{
?>
<div id="map_canvas" style="border:1px solid #333333; width: 250px; height: 200px"></div>
<?php 
$url = 'http://maps.google.com/maps/geo?q='.$lat.','.$lng.'&output=json&ie=utf8&oe=utf8&sensor=false&key=ABQIAAAA1QnAxBtPWpvkkIJ1M7uNRhSaZr1EoDksNVh5CWAzOfD4zrQihBTtbZTHEHq4q97m9-r8YVi8kTiliA';
$json = file_get_contents($url);
$arr = json_decode($json);
$address = $arr->Placemark[0]->address;
echo $address . '&nbsp;';
echo anchor('profile/mymap', 'แก้ไข');
}
?>
</div>

<h2>คนที่คุณกำลังติดตาม</h2>
<?php
if($friends == null)
{
	echo "<p>ยังไม่รู้จะตามใครใช่มั้ย?" . anchor('search', 'ค้นหาคนอื่นๆ') . "</p>";
}else{
	foreach($friends as $friendsId)
		{
			$friendsName = $this->usermodel->getName($friendsId);
			$friendsAvatar = $this->usermodel->getAvatar($friendsId);
?>

	<a class="tipsy-fade" href="user/id/<?=$friendsId;?>"  title="<?=$friendsName;?>"><img src="<?=$friendsAvatar;?>" alt="<?=$friendsName;?>" width="73" height="73" /></a>
	<div class="caption">
		<a href="user/id/<?=$friendsId;?>"><?=$friendsName;?></a>
</div>
<? } }?>
</div>

<div id="two">
<?php
	if($this->session->flashdata('error'))
	{ 
	echo '<div class="error">' . $this->session->flashdata('error') . '</div>';
	}
?>
<div class="item">
	
<div id='wallstatus'>
	<h3>คุณกำลังคิดอะไรอยู่ ?</h3>
	<?php echo form_open('profile/myWallPost'); ?>
	<textarea name='wallpost'></textarea>
	<label></label>
	<input type='submit' class='button' value='เขียนข้อความ'>
	</form>
</div>
</div>

<div class='item' id='updates'>

<?php foreach($wall as $arr): 
if($arr['wall_type'] == 'action')
	{
		echo $arr['wall_content'] . '<hr />';
	}
	elseif($arr['wall_type'] == 'normal')
	{
?>	
<h2><a href="<?=base_url() . 'user/id/' . $arr['user_id'];?>"><img width="32px" height="35px" src="<?=$this->usermodel->getAvatar($arr['user_id']);?>"><?=$arr['username'];?></a></h2>
<?=$arr['wall_content'] . '<h6>' . $this->usermodel->relativeTime($arr['wall_date']) . '&nbsp;&#183;&nbsp;'; ?><a href="javascript:if(confirm('Are you sure you want to delete this post?')==true){window.location='profile/deleteWall/<?=$arr['wall_id'];?>';}">ลบ</a></h6>
<div id='wallpost'>
	<h5>แสดงความคิดเห็น &nbsp;</h5>
	<div>
	<p>
	<?php echo form_open('profile/subWallPost/'.$arr["wall_id"]);?>
	<input name='comment' type='text' size='40'>
	<label></label>
	<input type='submit' class='button' value='เขียนความคิดเห็น'>
	</form>
	</p>
	</div>

</div>
<? } ?>
<div class='subitem'>
<?php 
$subWall = $this->wallmodel->getSubWall($arr['wall_id']); 
foreach ($subWall as $sub): ?>
<p>
<h4><a href="<?=base_url() . 'user/id/' . $sub['user_id'];?>"><img width="32px" height="35px" src="<?=$this->usermodel->getAvatar($sub['user_id']);?>"><?=$sub['username'];?></a></h4>
<?=$sub['sub_wall_content']; ?><a href="javascript:if(confirm('Are you sure you want to delete this comment?')==true){window.location='profile/deleteSubWall/<?=$sub['sub_wall_id'];?>';}"><h6><?=$this->usermodel->relativeTime($sub['sub_wall_date']); ?>&nbsp;&#183;&nbsp;ลบความคิดเห็น</h6></a>
</p>
<?php endforeach;?>
</div>
<label></label>
<?php endforeach;?>
</div>

<div id="more<?php echo $arr['wall_id']; ?>" class="morebox">
<a href="#" class="more" id="<?php echo $arr['wall_id']; ?>">ดูเพิ่มเติม</a>
</div>

</div>

<div id="three">
<div class="item">
<h2>รูปภาพล่าสุด [<?=anchor('profile/album', 'ดูทั้งหมด'); ?>]</h2><hr />
<p>
	<?php
	if($album == false)
	{
		echo "<i>คุณยังไม่ได้อัพโหลดภาพถ่ายใดๆเลย...</i>";
	}
	else
		foreach ($album as $row):			
	?>
<a href="profile/photo/<?=$row['photo_id'];?>">
<img width="42px" height="42px" src="<?=base_url() . 'application/userdata/profile_' . $row['user_id'] . '/photos/thumbs/' . $row['caption'];?>" alt="<?=$row['location']; ?>" >	
</a>
	<?php endforeach;?>
</p>
</div>
</div>
</div>
<!-- footer -->
<?php include('footer.php');?>
<!-- footer end -->
</div>
</body>
</html>